home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / commands / make / reader.c < prev    next >
C/C++ Source or Header  |  1990-07-15  |  3KB  |  128 lines

  1. /*************************************************************************
  2.  *
  3.  *  m a k e :   r e a d e r . c
  4.  *
  5.  *  Read in makefile
  6.  *========================================================================
  7.  * Edition history
  8.  *
  9.  *  #    Date                         Comments                       By
  10.  * --- -------- ---------------------------------------------------- ---
  11.  *   1    ??                                                         ??
  12.  *   2 23.08.89 cast to NULL added                                   RAL
  13.  *   3 30.08.89 indention changed                                    PSH,RAL
  14.  *   4 03.09.89 fixed LZ eliminated                                  RAL
  15.  * ------------ Version 2.0 released ------------------------------- RAL
  16.  *
  17.  *************************************************************************/
  18.  
  19. #include "h.h"
  20.  
  21.  
  22. /*
  23.  *    Syntax error handler.  Print message, with line number, and exits.
  24.  */
  25. void error(msg, a1)
  26. char *msg;
  27. char *a1;
  28. {
  29.   fprintf(stderr, "%s: ", myname);
  30.   fprintf(stderr, msg, a1);
  31.   if (lineno)  fprintf(stderr, " near line %d", lineno);
  32.   fputc('\n', stderr);
  33.   exit(1);
  34. }
  35.  
  36.  
  37. /*
  38.  *    Read a line into the supplied string.  Remove
  39.  *    comments, ignore blank lines. Deal with    quoted (\) #, and
  40.  *    quoted newlines.  If EOF return TRUE.
  41.  */
  42. bool getline(strs, fd)
  43. struct str *strs;
  44. FILE *fd;
  45. {
  46.   register char *p;
  47.   char          *q;
  48.   int            tmppos;
  49.  
  50.   strs->pos = 0;
  51.   for (;;) {
  52.     if (strs->pos >= strs->len -128)
  53.         strrealloc(strs);
  54.     if (fgets(*strs->ptr + strs->pos, strs->len - strs->pos, fd) == (char *)0)
  55.         return TRUE;        /*  EOF  */
  56.  
  57.     lineno++;
  58.  
  59.     while ((p = strchr(*strs->ptr + strs->pos, '\n')) == (char *)0) {
  60.         tmppos = strs->len -1;
  61.         strrealloc(strs);
  62.         if (fgets(*strs->ptr + tmppos, strs->len - tmppos, fd) == (char *)0)
  63.             error("Unexpected EOF",(char *)0);
  64.     }
  65.  
  66.  
  67.     if (p[-1] == '\\')
  68.     {
  69.         p[-1] = '\n';
  70.         strs->pos = p - *strs->ptr;
  71.         continue;
  72.     }
  73.  
  74.     p = *strs->ptr;
  75.     while (((q = strchr(p, '#')) != (char *)0) &&
  76.         (p != q) && (q[-1] == '\\'))
  77.     {
  78.         char    *a;
  79.  
  80.         a = q - 1;    /*  Del \ chr; move rest back  */
  81.         p = q;
  82.         while (*a++ = *q++)
  83.             ;
  84.     }
  85.     if (q != (char *)0)
  86.         {
  87.         q[0] = '\n';
  88.         q[1] = '\0';
  89.     }
  90.  
  91.     p = *strs->ptr;
  92.     while (isspace(*p))    /*  Checking for blank  */
  93.         p++;
  94.  
  95.     if (*p != '\0')
  96.         return FALSE;
  97.     strs->pos = 0;
  98.   }
  99. }
  100.  
  101.  
  102. /*
  103.  *    Get a word from the current line, surounded by white space.
  104.  *    return a pointer to it. String returned has no white spaces
  105.  *    in it.
  106.  */
  107. char  *gettok(ptr)
  108. register char **ptr;
  109. {
  110.   register char *p;
  111.  
  112.  
  113.   while (isspace(**ptr))    /*  Skip spaces  */
  114.     (*ptr)++;
  115.  
  116.   if (**ptr == '\0')    /*  Nothing after spaces  */
  117.     return ((char *)NULL);
  118.  
  119.   p = *ptr;        /*  word starts here  */
  120.  
  121.   while ((**ptr != '\0') && (!isspace(**ptr)))
  122.     (*ptr)++;    /*  Find end of word  */
  123.  
  124.   *(*ptr)++ = '\0';    /*  Terminate it  */
  125.  
  126.   return(p);
  127. }
  128.